# This is wrap of mclapply function for automatically select number 
#  of cores and switch between lapply and mclapply for different 
#  envrionments (e.g. windows and linux)
# 
# Author: guochun
###############################################################################

auto_lapply=function(X,FUN, ...){
	#check global settings about parallel calculation
	if(PARALLEL){
		#avoid nested parallel calculation
		PARALLEL=FALSE;
		re=mclapply(X,FUN,...,mc.cores=MC_CORES)
		PARALLEL=TRUE;
	}else{
		re=lapply(X,FUN,...)
	}
	return(re)
}
